﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using BOHVote.BLL;

namespace BOH.Information
{
    public partial class ApplyInfoManage : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (Request.QueryString["ID"] != null)
                {
                    NotifyClass.DeleteNotify(Request.QueryString["ID"].ToString());
                    BindInfo();
                }
                else
                {
                    BindInfo();
                }
            }
        }

        public void BindInfo()
        {
            DataSet dst = NotifyClass.getAllNotify();
            BindInfoList(dst);
        }

        public void BindInfoList(DataSet dst)
        {
            if (dst != null && dst.Tables[0].Rows.Count > 0)
            {
                AspNetPager1.RecordCount = dst.Tables[0].Rows.Count;
                if (AspNetPager1.RecordCount != 0)
                {
                    labNoRecord.Visible = false;
                    AspNetPager1.Visible = true;
                    PagedDataSource pds = new PagedDataSource();
                    pds.DataSource = dst.Tables[0].DefaultView;
                    pds.AllowPaging = true;
                    pds.CurrentPageIndex = AspNetPager1.CurrentPageIndex - 1;
                    pds.PageSize = AspNetPager1.PageSize;
                    ApplyInfoList.DataSource = pds;
                    ApplyInfoList.DataBind();
                }
                else
                {
                    ApplyInfoList.DataSource = null;
                    ApplyInfoList.DataBind();
                    AspNetPager1.Visible = false;
                    labNoRecord.Visible = true;
                }
            }
            else
            {
                AspNetPager1.Visible = false;
                labNoRecord.Visible = true;
                ApplyInfoList.DataSource = null;
                ApplyInfoList.DataBind();
            }
        }


        protected void AspNetPager1_PageChanged(object src, EventArgs e)
        {
            BindInfo();
        }

        public string getStatus(string value)
        {
            string returnValue = string.Empty;
            if (value == "A")
            {
                returnValue = "激活";
            }
            else
            {
                returnValue = "<font style='color:red'>未激活</font>";
            }

            return returnValue;
        }

        public string getVerify(string value)
        {
            string returnValue = string.Empty;
            if (value == "P")
            {
                returnValue = "已审核";
            }
            else
            {
                returnValue = "<font style='color:red'>未审核</font>";
            }

            return returnValue;
        }

        public string CastToDate(string value)
        {
            string returnValue = string.Empty;
            if (value.Trim().Length > 0)
            {
                returnValue = Convert.ToDateTime(value).ToString("yyyy-MM-dd");
            }

            return returnValue;
        }
    }
}
